package com.whj.apidriver.service.impl;

import com.whj.apidriver.remote.ServiceDriverUserClient;
import com.whj.apidriver.remote.ServiceMapClient;
import com.whj.apidriver.service.PointService;
import com.whj.internalcommon.dto.Car;
import com.whj.internalcommon.dto.ResponseResult;
import com.whj.internalcommon.request.ApiPointRequest;
import com.whj.internalcommon.request.PointsRequestDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: wanghaijun
 * @Date: 2023/1/20 - 01 - 20 - 17:04 
 * @Description: com.whj.apidriver.service.impl
 */

@Slf4j
@Service
public class PointServiceImpl implements PointService {

    @Autowired
    private ServiceDriverUserClient serviceDriverUserClient;

    @Autowired
    private ServiceMapClient serviceMapClient;

    /**
     * 根据车辆id上传车辆坐标信息
     * @param apiPointRequest
     * @return
     */
    @Override
    public ResponseResult upload(ApiPointRequest apiPointRequest) {

        //获取cardId
        Long carId = apiPointRequest.getCarId();

        //通过cardId 获取tid，trid 调用Service-driver-user接口
        ResponseResult<Car> carById = serviceDriverUserClient.getCarById(carId);
        String tid = carById.getData().getTid();
        String trid = carById.getData().getTrid();
        log.info(tid);
        log.info(trid);

        //调用地图去上传
        PointsRequestDTO pointsRequestDTO =new PointsRequestDTO();
        pointsRequestDTO.setTid(tid);
        pointsRequestDTO.setTrid(trid);
        pointsRequestDTO.setPoints(apiPointRequest.getPoints());

        ResponseResult upload = serviceMapClient.upload(pointsRequestDTO);
        return upload;
    }
}
